#include"process.h"
#include<string.h>
#include<unistd.h>

#define SIZE 101
#define STYLE '#'

//v1
void FlushProcess(double total,double current)
{
    const char* lable = "|/-\\";
    int len = strlen(lable);
    static int index = 0;
    char buffer[SIZE];
    memset(buffer,0,sizeof(buffer));
    
    double rate = current*100.0/total;
    int num = (int)rate;

    for(int i = 0;i < num ;i++ )
    {
        buffer[i] = STYLE;
    }
    printf("[%-100s][%.1lf%%][%c]\r",buffer,rate,lable[index++]);
    
    fflush(stdout);
    index %= len;

    if(num == 100)
    {
        printf("\n");
    }
}

//v2
//
//void process()
//{
//    int rate = 0;
//    char buffer[SIZE];
//    memset(buffer,0,sizeof(buffer));
//    const char* lable = "|/-\\";
//    int len  = strlen(lable);
//    while(rate <= 100)
//    {
//        printf("[%-100s][%d%%][%c]\r",buffer,rate,lable[rate%len]);
//        fflush(stdout);
//        buffer[rate] = STYLE;
//        rate++;
//        usleep(100000);
//    }
//    printf("\n");
//}
//
//
